<?php

namespace App\Models\Trip\OrderBusiness;

use Eloquent;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;

/**
 * App\Models\Trip\OrderBusiness\BusinessOrderSnMap
 *
 * @property int         $id
 * @property int         $trip_type     行程类型
 * @property string      $order_sn      系统内部订单单号
 * @property string      $trade_no      系统外部订单单号,和服务商对接 下单改签对应 out_order_sn , 退票对应 refund_sn
 * @property string      $order_service 订单服务商
 * @property string      $out_order_id  服务商订单id
 * @property int         $business      1 下单 2 改签 3 退票 ...
 * @property Carbon|null $created_at
 * @property Carbon|null $updated_at
 * @method static Builder|BusinessOrderSnMap newModelQuery()
 * @method static Builder|BusinessOrderSnMap newQuery()
 * @method static Builder|BusinessOrderSnMap query()
 * @method static Builder|BusinessOrderSnMap whereBusiness($value)
 * @method static Builder|BusinessOrderSnMap whereCreatedAt($value)
 * @method static Builder|BusinessOrderSnMap whereId($value)
 * @method static Builder|BusinessOrderSnMap whereOrderService($value)
 * @method static Builder|BusinessOrderSnMap whereOrderSn($value)
 * @method static Builder|BusinessOrderSnMap whereOutOrderId($value)
 * @method static Builder|BusinessOrderSnMap whereTradeNo($value)
 * @method static Builder|BusinessOrderSnMap whereTripType($value)
 * @method static Builder|BusinessOrderSnMap whereUpdatedAt($value)
 * @mixin Eloquent
 */
class BusinessOrderSnMap extends Model
{
    use HasFactory;

    const BUSINESS_TYPE_BOOK          = 1;// 下单
    const BUSINESS_TYPE_CHANGE        = 2;// 改签
    const BUSINESS_TYPE_TICKET_RETURN = 3;// 退票
    const BUSINESS_TYPE_SNAP          = 4;// 抢票

    protected $table = 'order_business_order_sn_map';
    protected $fillable
                     = [
            "trip_type",
            "order_sn",
            "trade_no",
            "order_service",
            "out_order_id",
            "business",
        ];

    public function getOrderSn(): string
    {
        return $this->getAttribute('order_sn');
    }

    public function getOutOrderSn(): string
    {
        return $this->getTradeNo();
    }

    public function getTradeNo(): string
    {
        return $this->getAttribute('trade_no');
    }

    public function getRefundSn(): string
    {
        return $this->getTradeNo();
    }

    public function getOrderService(): string
    {
        return $this->getAttribute('order_service');
    }

    public function getOutOrderId(): string
    {
        return $this->getAttribute('out_order_id');
    }

    public function isBookOrderBusiness(): bool
    {
        return $this->getBusiness() == 1;
    }

    public function getBusiness(): int
    {
        return $this->getAttribute('business');
    }

    public function isChangeOrderBusiness(): bool
    {
        return $this->getBusiness() == 2;
    }

    public function isTicketReturnBusiness(): bool
    {
        return $this->getBusiness() == 3;
    }

    public function isSnapBusiness(): bool
    {
        return $this->getBusiness() == 4;
    }

    public function getTripType(): int
    {
        return $this->getAttribute('trip_type');
    }
}
